package Lab05.Q6;

import java.util.HashMap;
import java.util.Map;

import static Lab05.Q6.Test.Path;

public class Folder extends File {

    private Map<String, Folder> folders = new HashMap<String, Folder>();
    private Map<String, File> files = new HashMap<String, File>();

    public Folder(String name) {
        super(name);
    }

    static void Folder() {
    }

    void addFile(File file) {
        if (file instanceof Folder) {
            folders.put(file.getName(), (Folder) file);
        } else {
            files.put(file.getName(), file);
        }
        this.setStorage(this.getStorage() + file.getStorage());
        System.out.println("添加" + file.getName() + "成功！\n");
    }

    void removeFile(File file) {//删除通过folder实现
        if (folders.containsKey(file.getName()))
            folders.remove(file.getName());
        else if (files.containsKey(file.getName()))
            files.remove(file.getName());
        else {
            System.out.println("不存在" + file.getName() + '\n');
            return;
        }
        System.out.println("Remove" + file.getName() + " Successfully\n");
    }
    void showFile(){
        System.out.println(this.getName() + "contain files :\n");
        for(String key:folders.keySet()){
            System.out.print("\t");
            System.out.println(folders.get(key));
        }
        for(String key:files.keySet()){
            System.out.print("\t");
            System.out.println(files.get(key));
        }
    }
    public void executeCommand() {
        Path= Path+'\\'+this.getName();
    }
    public String toString(){
        return this.getName()+" "+this.getPath()+" "+this.getTime()+" \n";
    }
}
